package com.demo.controller;

import com.demo.component.UserComponent;
import com.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Admin
 * Date: 2023-02-07
 * Time: 18:49
 */

@Controller
public class UserController {

    //属性注入
    //@Autowired  //自动装配
    //private UserService userService;

    //Setter注入
    //private  UserService userService;

    //@Autowired
    //public void setUserService(UserService userService) {
    //this.userService = userService;
    //}

    //构造方法注入
    private UserService userService;
    private UserComponent userComponent;

    @Autowired
    public UserController(UserService userService, UserComponent userComponent) {
        this.userService = userService;
        this.userComponent = userComponent;
    }

    public UserController(UserService userService,Integer num) {
        this.userService = userService;
    }


    public void sayHello() {
        System.out.println("Hi~");
        //只能在非静态方法中使用
        userService.doService();
    }
}
